import cv2
import os
import numpy as np

def gammaCorrection(inputImg, gamma):
    luts = np.zeros((256, 1), dtype=np.uint8)
    for i in range(256):
        # luts[i] = min(np.power(i, gamma), 255)
        luts[i] = np.power((np.float(i) / 255.0), gamma) * 255

    outputImg = cv2.LUT(inputImg, luts)
    return  outputImg


if __name__ == '__main__':
    srcImgPath = os.getcwd().strip('code\ch3') + '\pic\DIP3E_Original_Images_CH03\Fig0308(a)(fractured_spine).tif'
    srcImg = cv2.imread(srcImgPath, cv2.IMREAD_GRAYSCALE)
    destImg = gammaCorrection(srcImg, 0.4)
    cv2.imshow("src", srcImg)
    cv2.imshow("dest", destImg)
    cv2.waitKey(0)


